﻿@model SlamDunk.CMS.Model.ViewModel.ArticleViewForWrite

@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section header{
    <script type="text/javascript" src="~/kindeditor/kindeditor-min.js"></script>
    <script type="text/javascript" src="~/kindeditor/lang/zh_CN.js"></script>
    <script type="text/javascript" src="~/SwfUpload/swfupload.js"></script>
    <script type="text/javascript" src="~/SwfUpload/handlers.js"></script>
    <script type="text/javascript">
        var editor;     //定义kindeditor对象
        var swfu;       //定义上传图片控件
        var attach;     //定义上传附件控件
        $(function () {
            //初始化kindeditor
            KindEditor.ready(function (K) {
                editor = K.create('textarea[name="Content"]', {
                    resizeType: 1,                  //表示可拉伸收缩
                    allowFileManager: true,   //表示允许上传文件,
                    uploadJson: '/kindeditor/upload_json.ashx'
                });
            });

            //初始化异步上传图片控件
            swfu = new SWFUpload({
                // Backend Settings
                upload_url: "/Admin/Article/UploadImage",          //用户上传文件的处理程序
                post_params: {
                    "ASPSESSID": "@Session.SessionID"
                },

                // File Upload Settings
                file_size_limit: "2 MB",
                file_types: "*.jpg;*.gif;*.png;*.bmp",
                file_types_description: "JPG Images",
                file_upload_limit: 0,    // Zero means unlimited

                // Event Handler Settings - these functions as defined in Handlers.js
                // The handlers are not part of SWFUpload but are part of my website and control how
                // my website reacts to the SWFUpload events.
                swfupload_preload_handler: preLoad,
                swfupload_load_failed_handler: loadFailed,
                file_queue_error_handler: fileQueueError,
                file_dialog_complete_handler: fileDialogComplete,
                upload_progress_handler: uploadProgress,
                upload_error_handler: uploadError,
                upload_success_handler: showMessage,
                upload_complete_handler: uploadComplete,

                // Button settings
                button_image_url: '@Url.Content("~/SwfUpload/images/XPButtonNoText_160x22.png")',
                button_placeholder_id: "spanButtonPlaceholder",
                button_width: 160,
                button_height: 22,
                button_text: '<span class="button">请选择图片 <span class="buttonSmall">(2MB Max)</span></span>',
                button_text_style: '.button { font: 14px "微软雅黑"; } .buttonSmall { font: 14px; }',
                button_text_top_padding: 1,
                button_text_left_padding: 5,

                // Flash Settings
                flash_url: '@Url.Content("~/SwfUpload/swfupload.swf")',	                // Relative to this file

                flash9_url: '@Url.Content("~/SwfUpload/swfupload_FP9.swf")',	    // Relative to this file

                custom_settings: {
                    upload_target: "divFileProgressContainer"
                },

                // Debug Settings
                debug: false
            });

            //初始化异步上传图片控件
            attach = new SWFUpload({
                // Backend Settings
                upload_url: "/Admin/Article/UploadAttach",          //用户上传文件的处理程序
                post_params: {
                    "ASPSESSID": "@Session.SessionID"
                },

                // File Upload Settings
                file_size_limit: "40 MB",
                file_types: "*.*",
                file_types_description: "All",
                file_upload_limit: 0,    // Zero means unlimited

                // Event Handler Settings - these functions as defined in Handlers.js
                // The handlers are not part of SWFUpload but are part of my website and control how
                // my website reacts to the SWFUpload events.
                swfupload_preload_handler: preLoad,
                swfupload_load_failed_handler: loadFailed,
                file_queue_error_handler: fileQueueError,
                file_dialog_complete_handler: fileDialogComplete,
                upload_progress_handler: uploadProgress,
                upload_error_handler: uploadError,
                upload_success_handler: addAttachOk,
                upload_complete_handler: uploadComplete,

                // Button settings
                button_image_url: '@Url.Content("~/SwfUpload/images/XPButtonNoText_160x22.png")',
                button_placeholder_id: "spanButtonAttach",
                button_width: 160,
                button_height: 22,
                button_text: '<span class="button">请选择文件 <span class="buttonSmall">(40MB Max)</span></span>',
                button_text_style: '.button { font: 14px "微软雅黑"; } .buttonSmall { font: 14px; }',
                button_text_top_padding: 1,
                button_text_left_padding: 5,

                // Flash Settings
                flash_url: '@Url.Content("~/SwfUpload/swfupload.swf")',	                // Relative to this file

                flash9_url: '@Url.Content("~/SwfUpload/swfupload_FP9.swf")',	    // Relative to this file

                custom_settings: {
                    upload_target: "divFileProgressContainer"
                },

                // Debug Settings
                debug: false
            });

            //取消
            $('#btnCancel').click(function () {
                $.globalParas.closeComWindow();   //关闭弹出窗口
            })
        });

        //提交表单完成后执行方法
        function addFinished(jsonData) {
            if (jsonData.Status == '1') {
                window.top.window.$.messager.alert('OK', jsonData.Message);        //主窗口弹出消息提示
                $.globalParas.updateDataGridInTab();                                              //清除选中，刷新表格
                $.globalParas.closeComWindow();                                                    //关闭弹出窗口
            } else {
                window.top.window.$.messager.alert('Error', jsonData.Message);      //主窗口弹出消息提示
            }
        }

        /// <summary>
        /// 上传图片成功后执行的方法
        /// </summary>
        /// <param name="file"></param>
        /// <param name="serverData">从服务端返回的数据</param>
        function showMessage(file, serverData) {
            var data = serverData.split(':');
            if (data[0] == 'OK') {
                swfu.destroy();
                $('#txtImagePath').val(data[1]);
                $('#txtThumbPath').val(data[2]);
                //$('#imgPreview').attr('src', data[1]);
            } else {
                alert(data[1]);
            }
        }

        /// <summary>
        /// 上传附件成功后执行的方法
        /// </summary>
        /// <param name="file"></param>
        /// <param name="serverData">从服务端返回的数据</param>
        function addAttachOk(file, serverData) {
            var data = serverData.split(':');
            if (data[0] == 'OK') {
                attach.destroy();
                $('#txtAttachPath').val(data[1]);
                $('#txtAttachName').val(data[2]);
            } else {
                alert(data[1]);
            }
        }
    </script>
    <style type="text/css">
        body {
            font: 14px "微软雅黑";
            margin: 0;
            padding: 10px;
        }

        .tAdd {
            width: 100%;
            margin: 0 auto;
        }

            .tAdd td {
                padding: 5px;
            }

            .tAdd input[type=text] {
                width: 850px;
                height: 20px;
            }

            .tAdd textarea {
                width: 850px;
                height: 360px;
            }

            .tAdd input[type=button], .tAdd input[type=submit] {
                width: 85px;
                height: 35px;
                font: 14px;
            }

        .validText {
            color: #ff0000;
        }
    </style>
}

@using (Ajax.BeginForm("AddConfirm", new { controller = "Article" }, new AjaxOptions { OnSuccess = "addFinished" }, new { id = "frmAdd" }))
{
    <input type="hidden" name="ChannelId" value="@ViewBag.ChannelId" />
    <table class="tAdd">
        <tr>
            <td>姓名：</td>
            <td>
                @Html.TextBoxFor(x => x.Title)
                @Html.ValidationMessageFor(x => x.Title, string.Empty, new { @class = "validText" })
            </td>
        </tr>
        <tr>
            <td>头衔：</td>
            <td>
                @Html.TextBoxFor(x => x.Author)
                @Html.ValidationMessageFor(x => x.Author, string.Empty, new { @class = "validText" })
            </td>
        </tr>
        <tr>
            <td>图片：</td>
            <td>
                @Html.TextBoxFor(x => x.ImagePath, new { id = "txtImagePath", @readonly = "readonly", style = "width:685px;" })
                <input type="hidden" id="txtThumbPath" name="ThumbPath" value="" />
                <span id="spanButtonPlaceholder"></span>
            </td>
        </tr>
        <tr>
            <td>附件：</td>
            <td>
                @Html.TextBoxFor(x => x.SubTitle, new { id = "txtAttachPath", @readonly = "readonly", style = "width:685px;" })
                <input type="hidden" id="txtAttachName" name="Intitle" value="" />
                <span id="spanButtonAttach"></span>
            </td>
        </tr>
        <tr>
        <tr>
            <td>观点：</td>
            <td>
                @Html.TextAreaFor(x => x.Content, new { id = "txtContent", name = "Content" })
                @Html.ValidationMessageFor(x => x.Content, string.Empty, new { @class = "validText" })
            </td>
        </tr>
        <tr>
            <td></td>
            <td>@Html.CheckBox("IsTop")是否置顶</td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="submit" value="保存并发布" />
                <input type="button" id="btnCancel" value="取消" />
            </td>
        </tr>
    </table>
}